import actionTypes from '../actions/actionTypes'


const initState = {
    graph: {
        nodes: [
        ],
        links: [
        ]
    }, 
    updateGraph: {
        nodes: [],
        links: []
    },
    isLoading: false
}

export default (state = initState, action) => {
    switch(action.type) {
        case actionTypes.START_FETCH_OVERALL_GRAPH:
            return {
                ...state,
                isLoading: true
            }
        case actionTypes.FETCH_OVERALL_GRAPH_SUCCESS:
            return {
                ...state,
                isLoading: false,
                graph: action.payload.graph,
                updateGraph: action.payload.graph
            }
        case actionTypes.FETCH_OVERALL_GRAPH_FAILED:
            return {
                ...state,
                isLoading: false,
            }
        case actionTypes.CHANGE_OVERALL_GRAPH_BY_LEGEND:
            return {
                ...state,
                isLoading: false,
                updateGraph: action.payload.graph
            }
        default:
            return state
    }
}